package main

import "fmt"

// TreeNode 定义多叉树节点结构
type TreeNode struct {
	Value    int
	Children []*TreeNode
}

// TreeToList 将多叉树转换为兄弟节点相邻的列表
func TreeToList(root *TreeNode) []int {
	if root == nil {
		return nil
	}

	var result []int
	queue := []*TreeNode{root}

	for len(queue) > 0 {
		node := queue[0]
		queue = queue[1:]

		result = append(result, node.Value)
		queue = append(queue, node.Children...)
	}

	return result
}

func main() {
	// 构建示例中的树结构
	root := &TreeNode{Value: 1}
	node2 := &TreeNode{Value: 2}
	node3 := &TreeNode{Value: 3}
	node4 := &TreeNode{Value: 4}
	node5 := &TreeNode{Value: 5}
	node6 := &TreeNode{Value: 6}
	node7 := &TreeNode{Value: 7}

	root.Children = []*TreeNode{node2, node3}
	node2.Children = []*TreeNode{node4, node5}
	node3.Children = []*TreeNode{node6, node7}

	// 转换为列表并打印结果
	list := TreeToList(root)
	fmt.Println(list) // 输出: [1 2 3 4 5 6 7]
}
